import React from 'react';
import { renderEnable, renderState } from 'utils';
import moment from 'moment';
import { actions } from 'mirrorx';
{/*
可配置化种类：

1、表格头部字段 
    1、列表页表格头部字段集合 mainTableColumn
    2、编辑页表格头部字段集合 childTableColumn

2、编辑框的字段
    1、编辑页 直接显示在页面的编辑字段 FormField
    2、编辑页 需要点击表格的增行弹框编辑的字段 FormTableField
    3. 列表页查询区域  searchField

3.表头部的按钮  headerButtonSets

4.表行尾部按钮  columnButtonSets
*/}

//表头信息

//字段属性

//基本信息
const FormDataHeader = [
    {
        enname: "billCode",
        zhname: "单据号",
        type: "FormControl",
        edit: { 0: false, 1: false },
        hidepage: { 0: true }
    },
    {
        enname: "pkOrgId",
        showname: "pkOrgName",
        codename: "pkOrgCode",
        zhname: "隶属组织",
        type: "RefComponent",
        refname: "organization",
        param:{
            "AUTH_refdim":"pkOrg","AUTH_refcod":"B2B_RETAIL_YEARLYPLAN"
        },
        cascadeName:{
            paramkey: "EQ_organization.id",
            childtype: "DataHeader",
            refKey: "refpk",
            dtoKey: "pkOrgId",
            offers: "areaId",
            resetOffersFlag: true,
        },
        edit: true,
        required: true,
    },
    {
        enname: "billMakerName",
        zhname: "制单人",
        refname: "FormControl",
        edit: false,
        hidepage:{0:true},
        required: false,
    },
    {
        enname: "planYear",
        zhname: "计划年度",
        type: "DatePicker",
        format: "YYYY",
        required:true,
        edit: true,
    },

    {
        enname: "setDimensionId",
        codename: "setDimensionCode",
        showname: "setDimensionName",
        zhname: "设置维度",
        type: "Select",
        required:true,
        showcontrol: [{
            value: "01",
            refKey: "code",
            dtoKey: "setDimensionCode",
            layer: ["FormField", "DataHeader", "Field"],
            fields: ["storeId"]
        },{
            value: "02",
            refKey: "code",
            dtoKey: "setDimensionCode",
            layer: ["FormField", "DataHeader", "Field"],
            fields: ["channelId","areaId"]
        }],
        code: "SZWDB",
        edit: true,
        required: false,
    },
    {
        enname: "creationTime",
        zhname: "创建时间",
        type: "DatePicker",
        hidepage: { 0: true },
        edit: false,
        refname: "YYYY-MM-DD",
        required: false,
    },
    {
        enname: "areaId",
        codename: "areaCode",
        showname: "areaName",
        zhname: "零售片区",
        type: "RefComponent",
        alias:"pkOrgId",
        param:{
            AUTH_refdim : "area",
            AUTH_refcod : "B2B_RETAIL_YEARLYPLAN",
            "EQ_enableState":"0",
        },
        edit: true,
        refname: "departmentRef",
        required: true,
    },
    {
        enname:"ext01Name",
        zhname:"零售地区",
        required: false,
        hidepage:{0:true,1:true,2:false},
        type: "FormControl",
        edit: false
    },
    {
        enname:"ext02Name",
        zhname:"零售大区",
        required: false,
        hidepage:{0:true,1:true,2:false},
        type: "FormControl",
        edit: false
    },
    {
        enname: "channelId",
        codename: "channelCode",
        showname: "channelName",
        zhname: "客户渠道",
        type: "RefComponent",
        param:{
            AUTH_refdim : "channel",
            AUTH_refcod : "B2B_RETAIL_YEARLYPLAN",
            "EQ_enableState": "1",
        },
        // multiple: true,
        edit: true,
        refname: "custchantype",
        required: true,
    },
    {
        enname: "billStatusId",
        codename: "billStatusCode",
        showname: "billStatusName",
        zhname: "单据状态",
        type: "Select",
        code:"BILL_STATUS",
        hidepage: { 0: true },
        edit:false,
        required: true,
    },
    {
        enname: "isEnable",
        zhname: "启用状态",
        type: "Radio",
        hidepage: { 0: true },
        options: [{
            "key": 1,
            "value": "已启用"
        }, {
            "key": 2,
            "value": "停用"
        }],
        edit: false,
    },
    {
        enname: "numSum",
        zhname: "基础目标数量",
        type: "InputNumber",
        precision: 2,
        edit: false,
        required: false,
    },
    {
        enname: "amountSum",
        zhname: "基础目标金额",
        precision: 2,
        type: "InputNumber",
        edit: false,
        required: false,
    },
    {
        enname: "challengeTargetNum",
        zhname: "挑战目标数量",
        type: "InputNumber",
        precision: 2,
        edit: false,
        required: false,
    },
    {
        enname: "challengeTargetAmount",
        zhname: "挑战目标金额",
        type: "InputNumber",
        precision: 2,
        edit: false,
        required: false,
    },
    {
        enname: "excellentTargetNum",
        zhname: "卓越目标数量",
        type: "InputNumber",
        precision: 2,
        edit: false,
        required: false,
    },
    {
        enname: "excellentTargetAmount",
        zhname: "卓越目标金额",
        type: "InputNumber",
        precision: 2,
        edit: false,
        required: false,
    },
    {
        enname: "actualSumNum",
        zhname: "实际数量合计",
        type: "InputNumber",
        precision: 2,
        edit: false,
        required: false,
    },
    {
        enname: "actualSumAmount",
        zhname: "实际金额合计",
        type: "InputNumber",
        precision: 2,
        edit: false,
        required: false,
    },
    {
        enname: "storeId",
        codename: "storeCode",
        showname: "storeName",
        zhname: "门店",
        type: "RefComponent",
        edit: true,
        refname: "terminal",
        required: true,
    },
    {
        enname: "brandId",
        codename: "brandCode",
        showname: "brandName",
        zhname: "商品品牌",
        required: true,
        refname: 'brandref',
        type: "RefComponent",
        edit: true
    },
    {
        enname: "categoryId",
        codename: "categoryCode",
        showname: "categoryName",
        zhname: "商品品类",
        required: true,
        refname: 'terminalGoodsCate',
        type: "RefComponent",
        edit: true
    },
    {
        enname: "remark",
        zhname: "备注",
        type: "FormControl",
        componentClass: "textarea",
        pattern:/^\S*$/,
        message: "不能有空格",
        edit: true,
    }
];
const columnretailYearlyplanItem = [
    {
        title: "月份",
        dataIndex: "month",
        width:90,
        key: "month",
    },
    {
        title: "基础目标数量",
        dataIndex: "num",
        key: "num",
        width:110,
        renderType: "inputnumber",
        filedProps: {
            precision: 2,
            min: 0,
        }
    },
    {
        title: "基础目标金额",
        dataIndex: "amount",
        key: "amount",
        width:110,
        renderType: "inputnumber",
        filedProps: {
            precision: 2,
            min: 0,
        }
    },
    {
        title: "基础平均价",
        dataIndex: "baseAveragePrice",
        key: "baseAveragePrice",
        width:110,
        // renderType: "inputnumber",
        // filedProps: {
        //     precision: 2,
        //     min: 0,
        // }
    },
    {
        title: "挑战目标数量",
        dataIndex: "challengeTarget",
        key: "challengeTarget",
        width:110,
        renderType: "inputnumber",
        filedProps: {
            precision: 2,
            min: 0,
        }
    },
    {
        title: "挑战目标金额",
        dataIndex: "challengeAmount",
        key: "challengeAmount",
        width: 110,
        renderType: "inputnumber",
        filedProps: {
            precision: 2,
            min: 0,
        }
    },
    {
        dataIndex: "challengeAveragePrice",
        key: "challengeAveragePrice",
        title: "挑战平均价",
        width:110,
        // renderType: "inputnumber",
        // filedProps: {
        //     precision: 2,
        //     min: 0,
        // }
    },
    {
        title: "卓越目标数量",
        dataIndex: "excellentTarget",
        key: "excellentTarget",
        width: 110,
        validate: true,
        renderType: "inputnumber",
        filedProps: {
            precision: 2,
            min: 0,
        }
    },
    {
        title: "卓越目标金额",
        dataIndex: "excellentAmount",
        key: "excellentAmount",
        width: 110,
        validate: true,
        renderType: "inputnumber",
        filedProps: {
            precision: 2,
            min: 0,
        }
    },
    {
        title: "卓越平均价",
        dataIndex: "excellentAveragePrice",
        key: "excellentAveragePrice",
        width: 110,
        // validate: true,
        // renderType: "inputnumber",
        // filedProps: {
        //     precision: 2,
        //     min: 0,
        // }
    },
    {
        title: "实际数量",
        dataIndex: "actualNum",
        key: "actualNum",
        // width: 110,
        // renderType: "inputnumber",
        // filedProps: {
        //     precision: 2,
        //     min: 0,
        // }
    },
    {
        title: "实际金额",
        dataIndex: "actualAmount",
        key: "actualAmount",
        width: 110,
        // renderType: "inputnumber",
        // filedProps: {
        //     precision: 2,
        //     min: 0,
        // }
    },
    {
        title: "实际平均价",
        dataIndex: "actualAveragePrice",
        key: "actualAveragePrice",
        width: 110,
    }
]
//表单字段

export const FormField = {
    "DataHeader": {
        "title": "基础信息",
        "Field": FormDataHeader
    },
}

//表格弹框表单字段
export const FormTableField = {
}

//渲染成字表表格的头
export const childTableColumn = {
    "retailYearlyplanItem": {
        "title": "明细",
        "type": "grid",
        "column": columnretailYearlyplanItem
    },
}

//渲染成字表表格的头
export const mainTableColumn = [
    {
        title: "单据号",
        dataIndex: "billCode",
        key: "billCode",
        width:140,
        render: (text, record) => {
            return <a style={{ "cursor": "pointer" }}
                onClick={() => {
                    actions.routing.push(
                        {
                            pathname: 'RetailOrdersYear-edit',
                            search: `?search_id=${record.id}&btnPageFlag=2`,
                        }
                    );
                    // location.reload();
                }}
            >
                {text}
            </a >;
        }
    },
    {
        title: "所属组织",
        dataIndex: "pkOrgName",
        key: "pkOrgName",
    },
    {
        title: "制单人",
        dataIndex: "billMakerName",
        key: "billMakerName",
        width:100,
    },
    {
        title: "计划年度",
        dataIndex: "planYear",
        key: "planYear",
        width:100,
        render:(text) => {
            return moment(text)._d.getFullYear();
        }
    },
    {
        title: "设置维度",
        dataIndex: "setDimensionName",
        key: "setDimensionName",
        width:120,
    },
    {
        title: "创建时间",
        dataIndex: "creationTime",
        key: "creationTime",
        width: 120,
        render:(text)=> {
            return moment(text).format("YYYY-MM-DD");
        }
    },
    {
        title: "零售片区",
        dataIndex: "areaName",
        key: "areaName",
        width: 120,
    },
    {
        dataIndex: "channelName",
        key: "channelName",
        title: "客户渠道",
        width: 120,
    },
    {
        title: "单据状态",
        dataIndex: "state",
        key: "state",
        width: 100,
        render:(text)=>{
            return renderState(text);
        }
    },
    {
        title: "启用状态",
        dataIndex: "isEnable",
        key: "isEnable",
        width: 100,
        render:(text)=>{
            return renderEnable(text);
        }
    },
    {
        title: "门店",
        dataIndex: "storeName",
        key: "storeName",
        width: 120,
    },
    {
        title: "商品品类",
        dataIndex: "categoryName",
        key: "categoryName",
        width: 120,
    },
    {
        title: "商品品牌",
        dataIndex: "brandName",
        key: "brandName",
        width: 100,
    }
]

export const searchField = [
    {
        enname: "billCode",
        zhname: "单据号",
        type: "FormControl",
        edit:true,
        searchType:"like",
    },
    {
        enname: "pkOrg",
        zhname: "隶属组织",
        multiple: true,
        type: "RefComponent",
        param:{
            "AUTH_refdim":"pkOrg","AUTH_refcod":"B2B_RETAIL_YEARLYPLAN"
        },
        realRef:true,
        refname: "organization",
        edit: true,
    },
    {
        enname: "billMaker",
        zhname: "制单人",
        type: "RefComponent",
        refname: "personRef",
        realRef:true,
        edit: true,
    },
    {
        enname: "planYear",
        zhname: "计划年度",
        type: "RangePicker",
        format: "YYYY",
        rangeField:["planYear","planYear"],
        edit: true,
    },

    {
        enname: "setDimension",
        zhname: "设置维度",
        type: "Select",
        code: "SZWDB",
        edit: true,
    },
    {
        enname: "creationTime",
        zhname: "创建时间",
        type: "RangePicker",
        edit: true,
        rangeField:["creationTime","creationTime"],
        refname: "YYYY-MM-DD",
        required: false,
    },
    {
        enname: "area",
        zhname: "零售片区",
        type: "RefComponent",
        edit: true,
        realRef:true,
        refname: "departmentRef",
        required: false,
    },
    {
        enname:"ext01",
        zhname:"零售地区",
        required: false,
        realRef:true,
        refname:"departmentRef",
        type: "RefComponent",
        edit: true
    },
    {
        enname:"ext02",
        zhname:"零售大区",
        required: false,
        realRef:true,
        refname:"departmentRef",
        type: "RefComponent",
        edit: true
    },
    {
        enname: "channel",
        zhname: "客户渠道",
        type: "RefComponent",
        multiple: true,
        realRef:true,
        edit: true,
        param:{
            "EQ_enableState":"2"
        },
        refname: "custchantype",
        required: false,
    },
   
    {
        enname: "state",
        zhname: "单据状态",
        type: "Select",
        multiple:true,
        edit:true,
        code:"BILL_STATUS",
    },
    {
        enname: "store",
        zhname: "门店",
        type: "RefComponent",
        edit: true,
        multiple:true,
        realRef:true,
        refname: "terminal",
        required: false,
    },
    {
        enname: "brand",
        zhname: "商品品牌",
        required: false,
        multiple:true,
        realRef:true,
        refname: 'brandref',
        type: "RefComponent",
        edit: true
    },
    {
        enname: "category",
        zhname: "商品品类",
        required: false,
        multiple:true,
        realRef:true,
        refname: "terminalGoodsCate",
        type: "RefComponent",
        edit: true
    }
]

export const headerButtonSets = [
    {
        event: "ButtonAdd",
        zhname: "新增",
        color: 'primary',
        authcode: "001",
    },
    {
        event: "ButtonEnable",
        zhname: "启用",
        authcode: "014",
        method: "post",
        batch: true,
        ContentType: 'application/x-www-form-urlencoded;charset=utf-8',
        url: 'occ-b2b-order/b2b/retail-yearlyplans/enableOrder'
    },
    {
        event: "ButtonEnable",
        zhname: "停用",
        authcode: "015",
        method: "post",
        batch: true,
        ContentType: 'application/x-www-form-urlencoded;charset=utf-8',
        url: 'occ-b2b-order/b2b/retail-yearlyplans/disableOrder'
    }
]

export const columnButtonSets = {
    "delete": {
        event: "ButtonDel",
        zhname: "删除",
        batch: true,
        method: "post",
        ContentType: 'application/x-www-form-urlencoded;charset=utf-8',
        url: 'occ-b2b-order/b2b/retail-yearlyplans/deleteOrder'
    },
    "edit": true,
    "detail": true
}

// export default {mainTableColumn,searchField,headerButtonSets,
//     columnButtonSets,childTableColumn,FormTableField,FormField}
export const SelectCode = ["BILL_STATUS", "SZWDB","SP"]
